package cn.txun05.csmall.passport.controller;

import cn.txun05.csmall.passport.pojo.param.AdminAddNewParam;
import cn.txun05.csmall.passport.pojo.param.AdminLoginInfoParam;
import cn.txun05.csmall.commons.security.LoginPrincipal;
import cn.txun05.csmall.passport.service.IAdminService;
import cn.txun05.csmall.commons.web.JsonResult;
import cn.txun05.csmall.commons.web.ServiceCode;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/admin")
@Api(tags = "01.管理员管理模块")
@Slf4j
@Validated
public class AdminController {
    @Autowired
    private IAdminService adminService;

    @PostMapping("/add-new")
    @ApiOperation("添加管理员")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(AdminAddNewParam adminAddNewParam){
        log.debug("开始处理【添加管理员】的请求，参数：{}",adminAddNewParam);
        adminService.addNew(adminAddNewParam);
        return JsonResult.ok();
    }

    //localhost:9181/admin/login
    @PostMapping("/login")
    @ApiOperation("管理员登录")
    @ApiOperationSupport(order = 200)
    public JsonResult login(AdminLoginInfoParam adminLoginInfoParam){
        log.debug("开始处理【登录】的请求，参数：{}",adminLoginInfoParam);
        String jwt = adminService.login(adminLoginInfoParam);
        return JsonResult.ok(jwt);
    }

    //http://localhost:9181/admin/list
    @GetMapping("/list")
    @ApiOperation("查询管理员列表")
    @ApiOperationSupport(order = 300)
    public JsonResult list(@ApiIgnore @AuthenticationPrincipal LoginPrincipal user){
        log.debug("开始处理【查询管理员列表】的请求，无参数");
        log.debug("当事人id:{}",user.getId());
        log.debug("当事人username:{}",user.getUsername());
        return JsonResult.fail(ServiceCode.ERR_UNKNOWN,"此功能尚未开发");
    }

}
